package cn.com.pxto.commons;

import java.util.Calendar;
import java.util.Date;

public class CalendarUtils {

//		本月第一天
		public static Date getFirstOfMonth(Calendar calendar){
			/*Calendar calendar=Calendar.getInstance();*/
		//	int miniDate=calendar.getMinimum(Calendar.DAY_OF_MONTH);
			Calendar beginCalendar=Calendar.getInstance();
			/*endCalendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.YEAR), maxDate);*/
			beginCalendar.set(Calendar.DAY_OF_MONTH, 1);
			beginCalendar.set(Calendar.HOUR_OF_DAY, 0);
			beginCalendar.set(Calendar.SECOND, 0);
			beginCalendar.set(Calendar.MINUTE, 0);
			beginCalendar.set(Calendar.MILLISECOND, 0);
			return beginCalendar.getTime();
		}
//		本月最后一天
		public static Date getEndOfMonth(Calendar calendar){
			/*Calendar calendar=Calendar.getInstance();*/
			int maxDate=calendar.getMaximum(Calendar.DAY_OF_MONTH);
			Calendar endCalendar=Calendar.getInstance();
			/*endCalendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.YEAR), maxDate);*/
			endCalendar.set(Calendar.DAY_OF_MONTH, maxDate);
			endCalendar.set(Calendar.HOUR_OF_DAY, 23);
			endCalendar.set(Calendar.SECOND, 59);
			endCalendar.set(Calendar.MINUTE, 59);
			return endCalendar.getTime();
		}
//		下月第一天
		public static Date getFirstOfNextMonth(Calendar calendar){
			/*Calendar calendar=Calendar.getInstance();*/
			int netMonthMinDate=calendar.get(Calendar.MONTH)+1;
			Calendar nextMonth=Calendar.getInstance();
			if(netMonthMinDate == 12){
				nextMonth.set(Calendar.YEAR,calendar.get(Calendar.YEAR)+1);
				nextMonth.set(Calendar.MARCH, 0);
				nextMonth.set(Calendar.DAY_OF_MONTH, 1);
				nextMonth.set(Calendar.HOUR_OF_DAY, 0);
			}else{
				nextMonth.set(Calendar.MONTH, netMonthMinDate);
				nextMonth.set(Calendar.DAY_OF_MONTH, 1);
				nextMonth.set(Calendar.HOUR_OF_DAY, 0);
			}
			nextMonth.set(Calendar.HOUR_OF_DAY, 0);
			nextMonth.set(Calendar.SECOND, 0);
			nextMonth.set(Calendar.MINUTE, 0);
			return nextMonth.getTime();
		}
//		下月最后一天
		public static Date getEndOfNextMonth(Calendar calendar){
			/*Calendar calendar=Calendar.getInstance();*/
			int netMonthMinDate=calendar.get(Calendar.MONTH)+1;
			Calendar nextMonth=Calendar.getInstance();
			if(netMonthMinDate == 12){
				nextMonth.set(Calendar.YEAR,calendar.get(Calendar.YEAR)+1);
				nextMonth.set(Calendar.MARCH, 0);
				nextMonth.set(Calendar.DAY_OF_MONTH, 31);
				nextMonth.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY));
			}else{
				nextMonth.set(Calendar.MONTH, netMonthMinDate);
				nextMonth.set(Calendar.DAY_OF_MONTH, nextMonth.getMaximum(Calendar.DAY_OF_MONTH));
				nextMonth.set(Calendar.HOUR_OF_DAY, calendar.getMaximum(Calendar.HOUR_OF_DAY));
			}
			nextMonth.set(Calendar.HOUR_OF_DAY, 23);
			nextMonth.set(Calendar.SECOND, 59);
			nextMonth.set(Calendar.MINUTE, 59);
			return nextMonth.getTime();
		}
//		本周第一天,周日
		public static Date getFirstOfWeek(Calendar calendar){
			calendar.set(Calendar.DAY_OF_WEEK,1);
			calendar.set(Calendar.HOUR_OF_DAY, 0);
			calendar.set(Calendar.SECOND, 0);
			calendar.set(Calendar.MINUTE, 0);
			return calendar.getTime();
		}
//		本周最后天，周五
		public static Date getEndOfWeek(Calendar calendar){
			calendar.set(Calendar.DAY_OF_WEEK,7);
			calendar.set(Calendar.HOUR_OF_DAY, 23);
			calendar.set(Calendar.SECOND, 59);
			calendar.set(Calendar.MINUTE, 59);
			return calendar.getTime();
		}
		
}
